<template>
  <div class="page-hero" v-if="model">
    <div tag="div" class="topbar bg-black py-2 px-3 d-flex ai-center">
      <img src="../assets/logo.png" alt height="30" @click="$router.push('/')" />
      <div class="px-2 flex-1">
        <span class="text-white">王者荣耀</span>
        <span class="text-white ml-2">攻略站</span>
      </div>
      <router-link tag="div" to="/" class="text-white">更多英雄 &gt;</router-link>
    </div>
    <div class="top" :style="{'background-image':`url(${model.banner})`}">
      <div class="info text-white p-3 d-flex flex-column h-100 jc-end">
        <div class="fs-sm text-gary">{{model.title}}</div>
        <h2 class="my-2">{{model.name}}</h2>
        <div class="fs-sm text-gary">{{model.categories.title}}</div>
        <div class="d-flex jc-between pt-2">
          <div class="scores d-flex ai-center" v-if="model.scores">
            <span>难度</span>
            <span class="badge bg-yellow">{{model.scores.difficult}}</span>
            <span>技能</span>
            <span class="badge bg-blue">{{model.scores.skill}}</span>
            <span>攻击</span>
            <span class="badge bg-red">{{model.scores.attack}}</span>
            <span>生存</span>
            <span class="badge bg-dark-2">{{model.scores.live}}</span>
          </div>
          <span
            v-if="videoList[0]"
            class="text-gary fs-sm"
            @click="handleSkin"
          >皮肤 {{model.skins.length}} &gt;</span>
        </div>
      </div>
    </div>
    <!-- top end -->
    <!-- <img style="width:100%" :src="model.banner" alt=""> -->
    <div>
      <div class="px-3 bg-white">
        <div class="nav d-flex jc-around pt-3 pb-2 border-bottom">
          <div class="nav-item" :class="{active:swiperStatus===0}">
            <div class="nav-link" @click="swiperSwitch(0)">英雄初识</div>
          </div>
          <div class="nav-item" :class="{active:swiperStatus===1}">
            <div class="nav-link" @click="swiperSwitch(1)">进阶攻略</div>
          </div>
        </div>
      </div>
      <swiper ref="list" @slide-change="()=>swiperStatus=$refs.list.$swiper.realIndex">
        <swiper-slide>
          <div>
            <div class="p-3 bg-white border-bottom">
              <div class="d-flex">
                <router-link tag="button" to="/" class="btn btn-lg flex-1">
                  <i class="iconfont icon-cc-menu-circle"></i>
                  英雄介绍视频
                </router-link>
                <router-link tag="button" to="/" class="btn btn-lg flex-1 ml-2">
                  <i class="iconfont icon-cc-menu-circle"></i>
                  一图识英雄
                </router-link>
              </div>
              <!-- skill -->
              <div class="skills mt-4">
                <div class="d-flex jc-around">
                  <img
                    @click="currentSkillIndex=i"
                    :class="{active:currentSkillIndex===i}"
                    class="icon"
                    v-for="(item,i) in model.skills"
                    :key="i"
                    :src="item.icon"
                    alt
                  />
                </div>
                <div v-if="currentSkill">
                  <div class="d-flex pt-4 pb-3">
                    <h3 class="m-0">{{currentSkill.name}}</h3>
                    <span
                      class="text-gary-1 ml-4"
                    >(冷却值：{{currentSkill.delay}}消耗：{{currentSkill.cost}})</span>
                  </div>
                  <p class="border-bottom pb-3">{{currentSkill.desc}}</p>
                  <p class="text-gary">{{currentSkill.tip}}</p>
                </div>
              </div>
            </div>
            <!-- end of skills -->
            <m-card icon="cc-menu-circle" title="出装推荐" class="hero-items" plain>
              <div class="fs-xl">顺风出装</div>
              <div class="d-flex jc-around mt-3 border-bottom">
                <div v-for="item in model.items1" :key="item.name">
                  <img :src="item.icon" alt class="icon" />
                  <div class="fs-sm text-center">{{item.name}}</div>
                </div>
              </div>
              <div class="fs-xl mt-3">逆风出装</div>
              <div class="d-flex jc-around mt-3 border-bottom">
                <div v-for="item in model.items2" :key="item.name">
                  <img :src="item.icon" alt class="icon" />
                  <div class="fs-sm text-center">{{item.name}}</div>
                </div>
              </div>
            </m-card>
            <m-card icon="cc-menu-circle" title="使用技巧" plain>
              <p>{{model.useTip}}</p>
            </m-card>
            <m-card icon="cc-menu-circle" title="对抗技巧" plain>
              <p>{{model.battleTip}}</p>
            </m-card>
            <m-card icon="cc-menu-circle" title="团战思路" plain>
              <p>{{model.teamTip}}</p>
            </m-card>
            <m-card icon="cc-menu-circle" title="英雄关系" plain>
              <div class="fx-xl">最佳搭档</div>
              <div class="d-flex py-2" v-for="(item,i) in model.partners" :key="i">
                <img :src="item.hero.avatar" height="50" />
                <p class="flex-1 m-0 ml-3">{{item.desc}}</p>
              </div>
              <div class="border-bottom mt-3"></div>
            </m-card>
          </div>
        </swiper-slide>
        <swiper-slide>
          <div v-if="videoList[0]">
            <router-link tag="div" to="/error"
            v-for="(item,i) in videoList"
            :key="i"
            class="d-flex p-2"
            style="width:100%"
            >
              <div style="width:40%">
                <img class="w-100" :src="item.img" />
              </div>
              <div style="width:60%" class="d-flex flex-column jc-between px-2">
                <p class="m-0">{{item.title}}</p>
                <div class="d-flex jc-between fs-xs text-gary">
                  <span>{{item.playNum}}</span>
                  <span>{{model.updatedAt | date}}</span>
                </div>
              </div>
            </router-link>
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script>
import "../assets/font/iconfont.css";
import dayjs from "dayjs";
export default {
  props: {
    id: { required: true }
  },
  filters: {
    date(val) {
      return dayjs(val).format("MM/DD");
    }
  },
  data() {
    return {
      model: null,
      currentSkillIndex: 0,
      videoList: [],
      swiperStatus:0
    };
  },
  computed: {
    currentSkill() {
      return this.model.skills[this.currentSkillIndex];
    }
  },
  watch: {},
  created() {
    this.feachHero();
  },
  methods: {
    async feachHero() {
      const res = await this.$http.get(`heroes/${this.id}`);

      this.model = res.data;
      this.videoList = Array(10).fill(this.model.videos[0]);
    },
    handleSkin() {
      this.$router.push(`skins/${this.id}`);
    },
    swiperSwitch(i){
      if (i===1) {
        this.swiperStatus=1
        this.$refs.list.$swiper.slideTo(this.swiperStatus)
      }else{
        this.swiperStatus=0
        this.$refs.list.$swiper.slideTo(this.swiperStatus)
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../assets/scss/variables";
.page-hero {
  .top {
    height: 50vw;
    background: #fff no-repeat top center;
    background-size: auto 100%;
  }
  .info {
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
    .scores {
      .badge {
        margin: 0 0.25rem;
        display: inline-block;
        width: 1rem;
        height: 1rem;
        line-height: 1rem;
        text-align: center;
        border-radius: 50%;
        font-size: 0.75rem;
      }
    }
  }
  .skills {
    img.icon {
      border: 3px solid map-get($colors, "white");
      border-radius: 50%;
      width: 70px;
      height: 70px;
      &.active {
        border: 3px solid map-get($colors, "primary");
      }
    }
  }
  .hero-items {
    img.icon {
      width: 45px;
      height: 45px;
      border-radius: 50%;
    }
  }
}
</style>